package com.ayf.payment.game.api.service.payment.util;

import org.apache.commons.lang.StringUtils;

import java.util.Map;

public final class PackageHtmlPayementFormUtil {



    public static String packageHtmlPayementForm(Map<String, String> map, String action) {
        StringBuffer form = new StringBuffer();
        form.append("<form name='payform' id='payform' method='post' action='" + action + "'>");
        for (Map.Entry<String, String> entry : map.entrySet()) {
            String key = entry.getKey();
            String value =checkStrNull(entry.getValue());
            form.append("<input type='hidden' name='" + key + "' value='" + value + "'>");
        }
        form.append("</form>").append("<script type=\"text/javascript\"> window.onload = function () { if (document.readyState == \"complete\") {document.forms[0].submit();}}</script>");
        return form.toString();
    }

    private static String checkStrNull(String str) {
        if (StringUtils.isBlank(str) || "null".equals(str)) {
            return "";
        }
        return str.trim();
    }
}
